package com.ruijie.acl.task;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ruijie.acl.service.AclDeviceService;
import com.ruijie.batch.core.factory.SpringConfigAware;
import com.ruijie.batch.task.ItemOrientedTasklet;
import com.ruijie.batch.task.ItemProcessResult;
import com.ruijie.emp.batch.task.DeviceTaskUtils;
import com.ruijie.emp.device.Device;
import com.ruijie.foundation.exception.BusinessException;
import com.ruijie.foundation.utils.ExceptionUtils;

/**
 * 
 * <p>Title: SyncAclDeviceTask         </p>
 * <p>Description: ACL Device 信息自动同步 </p>
 * <p>Copyright: Copyright (c) 2009     </p>
 * <p>Company: Ruijie Co., Ltd.       </p>
 * <p>Create Time: 2009-9-14           </p>
 * <p>Update Time:                      </p>
 * <p>Updater:                          </p>
 * <p>Update Comments:                  </p>
 * @author ASAI
 */
public class SyncAclDeviceTask  implements ItemOrientedTasklet,SpringConfigAware {

    private Log logger = LogFactory.getLog(SyncAclDeviceTask.class);

    private AclDeviceService aclDeviceService;
    
	@SuppressWarnings("unchecked")
	public ItemProcessResult process(Object item){
		ItemProcessResult result = new ItemProcessResult();
        result.setItemInfo(DeviceTaskUtils.populateItemInfo((Device)item));
        
        try{
        	aclDeviceService.syncAclDevice((Device)item);
            result.setSuccess(true);
        }
        catch(Throwable e){
            result.setSuccess(false);
            Throwable cause = ExceptionUtils.resolveActualException(e);
            if(cause instanceof BusinessException){
                result.setDesc(((BusinessException)cause).toParameterizedMessage().toString());
            }
            else{
                result.setException(e);
            }
            logger.error("error while SyncAclDevice with exception:" + e);
        }
        return result;
    }

	public AclDeviceService getAclDeviceService() {
		return aclDeviceService;
	}

	public void setAclDeviceService(AclDeviceService aclDeviceService) {
		this.aclDeviceService = aclDeviceService;
	}
	
	
}
